package org.rendao.exception;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "tbf_error")
@XmlAccessorType(XmlAccessType.FIELD)
public class TBFError {

	public static final TBFError AUTH_ERROR = new TBFError("802", "User authentication error");
	
	public static final TBFError ASSOCIATION_DELETE_DENY = new TBFError("807", "Trying to delete a record associating to other data.");
	
	public static final TBFError SHADOWCOPY_SOURCE_NULL = new TBFError("809", "Shadow copy source object is null");
	
	private static final String SYSTEM_ERROR_CODE = "1003"; 
	
	@XmlElement
	private String errorCode;
	
	@XmlElement
	private String message;

	public TBFError() {
	}
	
	public TBFError(String errorCode, String message) {
		this.errorCode = errorCode;
		this.message = message;
	}
	
	public TBFError(Throwable throwable) {
		this.errorCode = SYSTEM_ERROR_CODE;
		this.message = throwable.getMessage();
	}
	
	public String getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
}
